<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var s = "babad"
        var longestPalindrome = function (s) {
            if(s.length<2){
                return s
            }
            var start = 0;
            var maxlength = 1;
            function expandAroundCenter(left,right){
                while(left>=0&&right<s.length&&s[left]==s[right]){
                    if(right-left+1>maxlength){
                        maxlength = right-left+1
                        start = left;
                    }
                    left--;
                    right++
                }
            }
            for(var i = 0;i<s.length;i++){
                expandAroundCenter(i-1,i+1);
                expandAroundCenter(i,i+1)
            }
            return s.slice(start,start+maxlength)
        }
        console.log(longestPalindrome(s))
    </script>
</body>
</html>